package protocol.work.connection;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;

import protocol.common.util.CJLog;

public class ConnectionManager {
	protected Log logger = CJLog.getLogConsole();
	
	private Map<String,AbstractConnection> connectionMap;
	
	public ConnectionManager(){
		this.connectionMap = new HashMap<String,AbstractConnection>();
	}
	
	public void addConnection(String key,AbstractConnection connection){
		this.connectionMap.put(key, connection);
	}
	
	public void addAndStartConnection(String key,AbstractConnection connection){
		this.addAndStartConnection(key, connection);
		logger.info("<连接控制器> 尝试启动连接["+key+"]!");
		connection.start();
	}
	
	public void startWork(){
		for(String key : connectionMap.keySet()){
			logger.info("<连接控制器> 尝试启动连接["+key+"]!");
			AbstractConnection connection = connectionMap.get(key);
			connection.start();
		}
	}
}
